"use client";
import { userInfoApi } from "@/api/login";
import { getUserMoneyApi, UserVipInfo } from "@/api/user";
import { server } from "@/utils/client";
import { useRequest } from "ahooks";
import ItemCom from "./component/ItemCom";
import ModalCom from "./component/ModalCom";
import "./page.scss";
import { ProfileHeader } from "./ProfileHeader";

/**
 * @description  前台用户VIP信息 接口地址：https://app.apifox.com/link/project/4790544/apis/api-201160713
 */
const getVipApi = async () => {
    return server
        .request<UserVipInfo>({
            url: "/v1/api/user/user_vip_info",
            method: "POST",
        })
        .then((res) => {
            if (res.code === 200) return res.data;
        });
};

const Profile = () => {
    const { data: userInfo } = useRequest<any, any>(userInfoApi, {
        pollingErrorRetryCount: 1,
        pollingWhenHidden: false,
    });
    const { data: userMoney } = useRequest<any, any>(getUserMoneyApi, {
        pollingErrorRetryCount: 1,
        pollingWhenHidden: false,
    });
    const { data: userVip } = useRequest<any, any>(getVipApi, {
        pollingErrorRetryCount: 1,
        pollingWhenHidden: false,
    });

    return (
        <div className="profile-box">
            <ProfileHeader userInfo={userInfo} userMoney={userMoney} userVip={userVip!} />
            <ItemCom />
            <ModalCom />
        </div>
    );
};

export default Profile;
